package com.test.service.impl;

import com.test.dao.IHouseMeterCurrentDao;
import com.test.dao.IHouseValveCurrentDao;
import com.test.model.HouseMeterCurrentData;
import com.test.service.IHouseMeterCurrentService;
import com.test.utils.HouseMeterCurrentGenerate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ZZF on 2017/6/29.
 */
@Service
public class HouseMeterCurrentServiceImpl implements IHouseMeterCurrentService {

    @Autowired
    IHouseMeterCurrentDao houseMeterCurrentDao;

    @Autowired
    IHouseValveCurrentDao houseValueCurrentDao;

//    @Override
//    public HouseMeterCurrentData getDate(int id) {
//
//        return houseMeterCurrentDao.get(HouseMeterCurrentData.class, id);
//    }

    @Override
    public void updateCurrentDate() {

        List<HouseMeterCurrentData> houseMeterAll = houseMeterCurrentDao.getAll(HouseMeterCurrentData.class);

        if (!houseMeterAll.isEmpty()){
            //判断户阀状态开关
            for (HouseMeterCurrentData currentData : houseMeterAll) {
                String houseFlag = null;
                Map<String, Object> houseValueMap = houseValueCurrentDao.findSwitchState(currentData.gethouseMeterId());

                if (houseValueMap!=null) {
                    boolean temp = (boolean) houseValueMap.get("switchState");
                    if (!temp) {
                        houseFlag = "0";
                    }
                }
                HouseMeterCurrentData generate = HouseMeterCurrentGenerate.generate(currentData, houseFlag);
                //改变户表的实时数据
                houseMeterCurrentDao.update(generate);
            }
        }

    }

    @Override
    public void updateData(HouseMeterCurrentData ss) {

        houseMeterCurrentDao.update(ss);
    }

    @Override
    public List<HouseMeterCurrentData> findStationBranch(int StationBranchId) {

        return houseMeterCurrentDao.findStationBranch(StationBranchId);
    }


}
